package com.k.base.jdk;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/**
 * @author k
 */
public class SizeOf {

    public static void main(String[] args) {
        // 7个数字字符
        String s1 = "1234567";
        byte[] b1 = s1.getBytes();
        System.out.println("7个数字字符1234567所占的字节数为:" + b1.length);

        // 7个英文字符
        String s2 = "abcdefg";
        byte[] b2 = s2.getBytes();
        System.out.println("7个英文字符abcdefg所占的字节数为:" + b2.length);

        // 7个英文符号字符
        String s3 = "::<>{}?";
        byte[] b3 = s3.getBytes();
        System.out.println("7个英文符号字符::<>{}?所占的字节数为:" + b3.length);

        // 7个中文汉字字符
        String s4 = "钓鱼岛是中国的";
        byte[] b4 = s4.getBytes();
        System.out.println("钓鱼岛是中国的所占的字节数为:" + b4.length);

        // 7个中文符号字符
        String s5 = "【】《》？：！";
        byte[] b5 = s5.getBytes();
        System.out.println("7个中文符号字符  【】《》？：！  所占的字节数为:" + b5.length);

        String s6 = "呵呵呵";
        byte[] b6utf8 = s6.getBytes(Charset.forName("UTF-8"));
        byte[] b6gbk = s6.getBytes(Charset.forName("GBK"));
        byte[] b6gb2312 = s6.getBytes(Charset.forName("GB2312"));
        byte[] b6gb18030 = s6.getBytes(Charset.forName("GB18030"));
        byte[] b6iso = s6.getBytes(Charset.forName("ISO-8859-1"));

        System.out.println("b6utf8:" + b6utf8.length);
        System.out.println("b6gbk:" + b6gbk.length);
        System.out.println("b6gb2312:" + b6gb2312.length);
        System.out.println("b6gb18030:" + b6gb18030.length);
        System.out.println("b6iso:" + b6iso.length);

        try {
            String b6ToStr = new String(b6utf8);
            System.out.println(b6ToStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
